package com.ficus.road.maintain.service.smartnew;

import com.ficus.road.maintain.core.model.smartnew.SmartDecisionExcelVO;
import com.ficus.road.maintain.core.model.smartnew.SmartDecisionResponse;
import com.ficus.road.maintain.handler.smartdecision.enums.SmartDecisionStrategyEnum;
import com.ficus.road.maintain.handler.smartdecision.strategy.ISmartDecisionStrategy;
import com.google.common.collect.Maps;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;

/**
 * @author xiawen
 * 工厂模式 + 策略模式
 * @date 2022/7/20 下午4:11
 */
@Component
@RequiredArgsConstructor
public class StrategySmartDecisionService {

    private final List<ISmartDecisionStrategy> smartDecisionStrategyList;

    private final Map<SmartDecisionStrategyEnum, ISmartDecisionStrategy> smartDecisionStrategyMap = Maps.newConcurrentMap();

    @PostConstruct
    void init() {
        smartDecisionStrategyList.forEach(strategy -> smartDecisionStrategyMap.put(strategy.getStrategy(), strategy));
    }


    public SmartDecisionResponse smartDecisionCalculate(SmartDecisionStrategyEnum smartDecisionStrategyEnum, List<SmartDecisionExcelVO> params, SmartDecisionResponse response) {
        return smartDecisionStrategyMap.get(smartDecisionStrategyEnum).process(params, response);
    }
}
